﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stateless
{
    public partial class StateMachine<TState, TTrigger, TData0>
    {
        //internal class TransitioningTriggerBehaviour : TriggerBehaviour
        //{
        //    readonly TState _destination;
        //    readonly Func<TData0, bool> _guard;

        //    public TransitioningTriggerBehaviour(TTrigger trigger, TState destination, Func<TData0, bool> guard)
        //        : base(trigger)
        //    {
        //        _destination = destination;
        //        _guard = guard;
        //    }

        //    public override bool ResultsInTransitionFrom(TState source, object[] args, out TState destination)
        //    {
        //        destination = _destination;
        //        return true;
        //    }

        //    public override bool Guard(TData0 args)
        //    {
        //        return _guard(args);
        //    }
        //}

        internal class TransitioningTriggerBehaviour : TriggerBehaviour
        {
            readonly TState _destination;
            readonly Func<TData0, bool> _guard;

            public TransitioningTriggerBehaviour(TTrigger trigger, TState destination, Func<TData0, bool> guard)
                : base(trigger)
            {
                _destination = destination;
                _guard = guard;
            }

            public override bool ResultsInTransitionFrom(TState source, TData0 args, out TState destination)
            {
                destination = _destination;
                return true;
            }

            public override bool Guard(TData0 args)
            {
                if (args != null)
                {
                    var myObject = args;
                    return _guard(myObject);
                }

                return false;
            }
        }
    }
}
